﻿using AiBLSmartEdu.Module.CreditAnalysis.API.DTOs;
using AiBLSmartEdu.Module.CreditAnalysis.API.Services;
using FrameworkCore;
using FrameworkCore.Controllers;
using FrameworkCore.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AiBLSmartEdu.Module.CreditAnalysis.API.Controllers;

/// <summary>
/// 征信文件解析服务
/// </summary>
[AllowAnonymous]
public class DocumentController : BaseModuleController
{
    private readonly DocumentServices _documentServices;

    public DocumentController(
        DocumentServices documentServices)
    {
        _documentServices = documentServices;
    }

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="filter">分页输入模型</param>
    /// <returns></returns>
    [HttpGet("Page")]
    public async Task<PageResult<DocumentOutputModel>> Pagination([FromQuery] DocumentPaginationFilter filter)
    {
        return await _documentServices.PageAsync(filter);
    }

    /// <summary>
    /// 创建文档
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Result> Create(DocumentCreateInputModel input)
    {
        await _documentServices.CreateAsync(input);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 修改文档
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPut]
    public async Task<Result> Update(DocumentUpdateInputModel input)
    {
        await _documentServices.UpdateAsync(input);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 批量删除文档
    /// </summary>
    /// <returns></returns>
    [HttpDelete("{ids}")]
    public async Task<Result> BulkDeletes(string ids)
    {
        await _documentServices.DeleteAsync(ids);
        return await Result.SucceedAsync();
    }
}
